<?php

namespace app\common\model\xiluedu;

use think\Db;
use think\Model;
use traits\model\SoftDelete;

class Banner extends Model
{

    // 表名
    protected $name = 'xiluedu_banner';

    protected $deleteTime = false;
    // 追加属性
    protected $append = [
        'status_text'
    ];

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function getThumbImageAttr($value,$data){
        return $value ? cdnurl($value,true) : $value;
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 获取状态正常的banner
     * @param $group
     * @param $cityId
     * @param boolean $minapp true 取小程序的
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getBanners($group,$minapp) {
        static::where('group', $group)->where('status',1)->update(['show_count'=>Db::raw('show_count+1')]);
        $query = static::where('group', $group)->where('status',1)->order('weigh')->field('id,minapp_url,thumb_image');
        if($minapp) {
            //$query->where('minapp_url','<>', '');
        }
        return $query->select();
    }
}
